package com.easysoft.framework.product.service;

import com.easysoft.commons.utils.UUIDUtils;
import com.easysoft.framework.annotation.jdbc.DataSource;
import com.easysoft.framework.beans.Page;
import com.easysoft.framework.product.mapper.SysProductMapperExtd;
import com.easysoft.framework.product.model.SysProduct;
import com.easysoft.framework.product.model.SysProductQuery;
import com.easysoft.framework.product.model.SysProductView;
import com.easysoft.framework.warning.model.SysWarningTips;
import com.easysoft.framework.warning.model.SysWarningTipsView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service("service.SysProductService")
public class SysProductService {
    @Autowired
    @Qualifier("mapper.SysProductMapperExtd")
    private SysProductMapperExtd sysProductMapperExtd;


    @DataSource(DataSource.SLAVE)
    public List<SysProductView> selectSysProductByPage(Page page, SysProductQuery query) {
        int maxRow = sysProductMapperExtd.selectCountAllProduct(query);
        if (maxRow == 0){
            return new ArrayList<SysProductView>();
        }
        page.setMaxRow(maxRow);
        return sysProductMapperExtd.selectSysProductByPage(page,query);
    }

    @DataSource(DataSource.MASTER)
    public int addSysProduct(SysProduct sysProduct) {
        sysProduct.setId(UUIDUtils.getUUID());
        sysProduct.setCreateTime(new Date());
        return sysProductMapperExtd.insertSelective(sysProduct);
    }

    @DataSource(DataSource.SLAVE)
    public SysProduct selectSysProductById(String id) {

        return sysProductMapperExtd.selectByPrimaryKey(id);
    }

    @DataSource(DataSource.MASTER)
    public int updateSysProduct(SysProduct sysProduct){
        return sysProductMapperExtd.updateByPrimaryKeySelective(sysProduct);
    }

    @DataSource(DataSource.MASTER)
    public int deleteSysProduct(String id) {

        return sysProductMapperExtd.deleteByPrimaryKey(id);
    }
}
